
$(function () {
    $("#submit").click(function (event) {
        // 阻止按钮默认的提交表单的事件
       event.preventDefault();
       var oldpwdE = $("input[name=oldpwd]");
       var newpwdE = $("input[name=newpwd]");
       var newpwdE2 = $("input[name=newpwd2]");

       var oldpwd = oldpwdE.val();
       var newpwd = newpwdE.val();
       var newpwd2 = newpwdE2.val();

       console.log(oldpwd, newpwd, newpwd2)

        // 1.要在模板的meta标签中渲染一个csrf-token
        // 2.在ajax请求的头部中设置x-CSRFtoken
        jfajax.post({
            'url': '/cms/resetpwd/',
            'data': {
                'oldpwd': oldpwd,
                'newpwd': newpwd,
                'newpwd2': newpwd2
            },
            'success': function(data){
                // code == 200
                // code != 200
                if(data['code'] == 200){
                    jfalert.alertSuccessToast("恭喜,密码修改成功!");
                    oldpwdE.val("");
                    newpwdE.val("");
                    newpwdE2.val("");
                }else {
                    var message = data['message'];
                    jfalert.alertInfo(message);
                }
            },
            'fail':function (error) {
                jfalert.alertNetworkError();
            }
        })
    });

});
